#include <my_header.h>
#define BUFFER_SIZE 1024
/* Usage: ./2_large_cie_cp src_file dest_file */
int main(int argc, char *argv[]){                                  
    ARGS_CHECK(argc, 3);
    int fdr = open(argv[1], O_RDONLY);
    ERROR_CHECK(fdr, -1, "open_read");
    int fdw = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0666);
    ERROR_CHECK(fdw, -1, "open_write");

    char buf[BUFFER_SIZE] = { 0 }; // 使用char数组的原因是方便控制内存大小
    // while(1)
    // {
    //     memset(buf, 0, sizeof(buf));
    //     ssize_t sret = read(fdr, buf, sizeof(buf));
    //     if(sret == 0)
    //     {
    //         break;
    //     }
    //     write(fdw, buf, sret);
    // }// 循环正常结束时 文件已经读取写入完成
    // 上面代码可以写成下面的while循环
    ssize_t read_count;

    while((read_count = read(fdr, buf, sizeof(buf))) >0 )
    {
        write(fdw, buf, read_count);
    }

    close(fdr);
    close(fdw);

    return 0;
}


